package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendanceMonthlyAddDTO;
import org.jsola.hr.dto.AttendanceMonthlyUpdateDTO;
import org.jsola.hr.entity.AttendanceMonthlyDO;
import org.jsola.hr.query.AttendanceMonthlyQuery;
import org.jsola.hr.service.IAttendanceMonthlyService;
import org.jsola.hr.vo.AttendanceMonthlyVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendanceMonthlyTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendanceMonthlyService attendanceMonthlyService;

    /**
     * 生成add测试数据
     * @return AttendanceMonthlyAddDTO
     */
    public AttendanceMonthlyAddDTO getAttendanceMonthlyAddDTO(){
        AttendanceMonthlyAddDTO attendanceMonthlyAddDTO = new AttendanceMonthlyAddDTO();
        attendanceMonthlyAddDTO.setEmpId(getRandomValue("varchar",32));
        attendanceMonthlyAddDTO.setNumber(getRandomValue("varchar",32));
        attendanceMonthlyAddDTO.setYear(getRandomValue("varchar",32));
        attendanceMonthlyAddDTO.setMonth(getRandomValue("varchar",32));
        attendanceMonthlyAddDTO.setLateTimes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setLateDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setLateMinutes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setLeaveTimes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setLeaveDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setLeaveMinutes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setAbsenteeismTimes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setAbsenteeismDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setUncheckedTimes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setUncheckedDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setSupplementTimes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setSupplementDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setOverallTimes(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setOverallDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setCompanyId(getRandomValue("varchar",32));
        attendanceMonthlyAddDTO.setOthersDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setOthersDedRemark(getRandomValue("varchar",255));
        attendanceMonthlyAddDTO.setSocDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setPfDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setPersonTaxDed(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setWorkingDays(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setTeamCommission(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setBusinessCommission(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setOvertimePay(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setSubsidy(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceMonthlyAddDTO.setStatus(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendanceMonthlyAddDTO.setRemark(getRandomValue("varchar",255));
        return attendanceMonthlyAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendanceMonthlyUpdateDTO
     */
    public AttendanceMonthlyUpdateDTO getAttendanceMonthlyUpdateDTO(AttendanceMonthlyVO attendanceMonthlyVO){
        return attendanceMonthlyService.selectDOById(attendanceMonthlyVO.getId(), SITE_ID).to(AttendanceMonthlyUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendanceMonthlyQuery
     */
    public AttendanceMonthlyQuery getAttendanceMonthlyQuery() {
        AttendanceMonthlyQuery attendanceMonthlyQuery = new AttendanceMonthlyQuery();
        List<AttendanceMonthlyDO> attendanceMonthlyDOList = attendanceMonthlyService.list(new AttendanceMonthlyDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendanceMonthlyDOList)) {
            AttendanceMonthlyDO attendanceMonthlyDO = attendanceMonthlyDOList.get(0);
            attendanceMonthlyQuery = attendanceMonthlyDO.to(AttendanceMonthlyQuery.class);
            if (attendanceMonthlyDO.getGmtCreate() != null) {
                attendanceMonthlyQuery.setGmtCreateStart(DateKit.getBeforeDay(attendanceMonthlyDO.getGmtCreate(),-1));
                attendanceMonthlyQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendanceMonthlyDO.getGmtCreate(),1));
            }
            if (attendanceMonthlyDO.getGmtModified() != null) {
                attendanceMonthlyQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendanceMonthlyDO.getGmtModified(),-1));
                attendanceMonthlyQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendanceMonthlyDO.getGmtModified(),1));
            }
        }
        return attendanceMonthlyQuery;
    }

    /**
     * 保存示例
     * @return AttendanceMonthlyVO
     */
    public AttendanceMonthlyVO saveAttendanceMonthlyExample(){
        AttendanceMonthlyAddDTO addDTO = this.getAttendanceMonthlyAddDTO();
        AttendanceMonthlyVO attendanceMonthlyVO = attendanceMonthlyService.save(addDTO,buildTokenUser());
        return attendanceMonthlyVO;
    }


}

